package com.foryou.wechat.controller;

import com.foryou.wechat.common.Constants;
import com.foryou.wechat.model.dto.SubjectDTO;
import com.foryou.wechat.service.SubjectService;
import com.foryou.wechat.utils.Response;
import com.foryou.wechat.utils.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by Lee.
 */
@RestController
@RequestMapping("/v/subject")
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    @PostMapping("/addSubject")
    public Response addSubject(String name) {
        if (subjectService.addSubject(name) > 0) {
            return Response.success();
        }
        return Response.failure(Constants.OPERATION_FAILURE);
    }

    @PostMapping("/updateSubject")
    public Response updateSubject(@RequestBody SubjectDTO subjectDTO) {

        ValidatorUtils.validateEntity(subjectDTO);
        if (subjectService.updateSubject(subjectDTO) > 0) {
            return Response.success();
        }
        return Response.failure(Constants.OPERATION_FAILURE);
    }

    @GetMapping("/querySelectList")
    public Response querySelectList() {
        return subjectService.querySelectList();
    }

    @GetMapping("/querySelectListForSys")
    public Response querySelectListForSys(@RequestParam Map<String,Object> params) {
        return subjectService.querySelectList(params);
    }


    @GetMapping("/getSubjectInfo")
    public Response getSubjectInfo(@RequestParam Long subjectId) {
        return subjectService.getSubjectDetail(subjectId);
    }


}
